package com.es.dao.factory;

import java.util.concurrent.ConcurrentHashMap;

import org.apache.log4j.Logger;
import com.es.exception.dao.ESDataAccessException;


public class DAOFactory {

	private static final Logger log = Logger.getLogger(DAOFactory.class);
	
	private static ConcurrentHashMap<String, Object> daoHashmap= new ConcurrentHashMap<String, Object>();
	public static final String SALESWORKFORCE_DAO = "com.es.dao.SalesWorkForceDAO"; 
	public static final String LEAD_DAO = "com.es.dao.LeadDAO"; 
	public static final String BUSINESS_RULE_DAO = "com.es.dao.BusinessRuleDAO"; 
	public static final String PROPERTY_DAO = "com.es.dao.PropertyDAO"; 
	public static final String VALUE_DAO = "com.es.dao.ValueDAO"; 
	public static final String LEAD_QUALIFICATION_DAO = "com.es.dao.LeadQualificationDAO"; 
	public static final String CONTACT_DAO = "com.es.dao.ContactDAO";
	public static final String CLIENT_DAO = "com.es.dao.ClientDAO";
	public static final String BUSINESS_CONTACT_DAO = "com.es.dao.BusinessContactDAO";
	
	public static Object getDataAccessObject(String className){
		
		Object obj = null;
		
			try{
				if(daoHashmap.containsKey(className)){
					return daoHashmap.get(className);
				}else{
					Class c = Class.forName(className);
					obj = c.newInstance();
					daoHashmap.put(className, obj);
					return obj;
				}
			}catch (Exception e) {
				log.error("Exception :" + className );
				throw new ESDataAccessException("Cannot create Data Access Object for class : " + className,e);
			}

	}
	
}
